﻿Shader "Custom/NewSurfaceShader" {
	Properties {
		_Color ("Color", Color) = (1,1,1,1)
		_MainTex ("Albedo (RGB)", 2D) = "white" {}
		_Glossiness ("Smoothness", Range(0,1)) = 0.5
		_GridTex("背景框", 2D) = "white" {}
		_Metallic ("Metallic", Range(0,1)) = 0.0
		_SelectTex("选择背景", 2D) = "white" {}
	}
	SubShader {
		Tags { "RenderType"="Opaque" }
		LOD 200
		
		CGPROGRAM
		// Physically based Standard lighting model, and enable shadows on all light types
		#pragma surface surf Standard fullforwardshadows

		// Use shader model 3.0 target, to get nicer looking lighting
		#pragma target 3.0

		sampler2D _MainTex;
		sampler2D _GridTex;
		sampler2D _SelectTex;

		struct Input {
			float2 uv_MainTex;
			float2 uv2_GridTex;
			float4 color : COLOR0;
		};

		half _Glossiness;
		half _Metallic;
		fixed4 _Color;

		void surf (Input IN, inout SurfaceOutputStandard o) {
			// Albedo comes from a texture tinted by color
			fixed4 col;
			if (IN.color.a <= 0.1)
			{
				IN.color.a = 1;
				fixed4 colorShadow = tex2D(_SelectTex, IN.uv2_GridTex);//TRANSFORM_TEX(v.uv2, _GridTex)
				if (colorShadow.r == colorShadow.g)//白色
				{
					col = tex2D(_MainTex, IN.uv_MainTex) * IN.color * _Color;
				}
				else
				{
					col = colorShadow;
				}
			}
			else
			{
				col = tex2D(_MainTex, IN.uv_MainTex)*  IN.color * tex2D(_GridTex, IN.uv2_GridTex) * _Color;
			}

			o.Albedo = col.rgb;
			// Metallic and smoothness come from slider variables
			o.Metallic = _Metallic;
			o.Smoothness = _Glossiness;
			o.Alpha = col.a;
		}
		ENDCG
	}
	FallBack "Diffuse"
}
